import React from 'react';
import {
  View,
  Text,
  ScrollView,
  StyleSheet,
  useColorScheme,
  TouchableOpacity,
} from 'react-native';
import { useRoute, useNavigation, RouteProp } from '@react-navigation/native';
import { RootStackParamList } from '../types';

type NewsDetailScreenRouteProp = RouteProp<RootStackParamList, 'NewsDetail'>;

const NewsDetailScreen: React.FC = () => {
  const isDarkMode = useColorScheme() === 'dark';
  const route = useRoute<NewsDetailScreenRouteProp>();
  const navigation = useNavigation();
  const { news } = route.params;

  return (
    <ScrollView style={styles.container}>
      <TouchableOpacity 
        style={styles.backButton} 
        onPress={() => navigation.goBack()}
      >
        <Text style={styles.backButtonText}>← 返回</Text>
      </TouchableOpacity>
      
      <Text style={[styles.title, isDarkMode && styles.lightText]}>
        {news.title}
      </Text>
      
      <Text style={styles.publishTime}>
        发布时间: {news.publishTime}
      </Text>
      
      <View style={styles.contentContainer}>
        <Text style={[styles.content, isDarkMode && styles.lightText]}>
          {news.content}
        </Text>
      </View>
      
      {/* 底部空间 */}
      <View style={{height: 40}} />
    </ScrollView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 16,
  },
  backButton: {
    marginBottom: 16,
  },
  backButtonText: {
    color: '#2196F3',
    fontSize: 16,
    fontWeight: '500',
  },
  title: {
    fontSize: 24,
    fontWeight: 'bold',
    marginBottom: 8,
    color: '#333',
  },
  lightText: {
    color: '#fff',
  },
  publishTime: {
    fontSize: 14,
    color: '#888',
    marginBottom: 20,
  },
  contentContainer: {
    backgroundColor: '#fff',
    padding: 16,
    borderRadius: 8,
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 1 },
    shadowOpacity: 0.1,
    shadowRadius: 2,
    elevation: 2,
  },
  content: {
    fontSize: 16,
    lineHeight: 24,
    color: '#333',
  }
});

export default NewsDetailScreen;